//
//  VideoViewController.m
//  pocketNews
//
//  Created by DS on 2018/10/26.
//  Copyright © 2018年 徐双. All rights reserved.
//

#import "VideoViewController.h"
#import "LXScollTitleView.h"
#import "LXScrollContentView.h"
#import "VedioSonViewController.h"


@interface VideoViewController ()

@property (nonatomic, strong) LXScollTitleView *titleView;

@property (nonatomic, strong) LXScrollContentView *contentView;

Strong UIView * BlueView;


//装标题
Strong NSMutableArray * titleArr;

//装视频Id

Strong NSMutableArray * videoIdArr;


- (void)reloadData;

@end

//网络
@implementation VideoViewController (NetWorking)

//新闻接口
- (void)getData{
    
    
    
    [self showprogressHUD];
    NSDictionary *parameters = @{
                                 
                                 @"type":@"",
                                 
                                 @"key":@"c6e4817b12d373379556ffb70a5af0cb"
                                 
                                 }.mutableCopy;
    
    [[AFAppDotNetAPIClient sharedClient] POST:@"http://api.iclient.ifeng.com/ifengvideoList" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
    
        
            for (NSDictionary * dic in responseObject[0][@"types"]) {

                [self.titleArr addObject:dic[@"name"]];
                
                [self.videoIdArr addObject:dic[@"id"]];
                
                
            }
        
        [self reloadData];
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
        
        
    }];
}

@end

@implementation VideoViewController

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    
    self.navigationController.navigationBar.hidden = YES;
    
    
    
}




- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.BlueView];
    
    [self setupUI];
    
    
    [self getData];
    
}


- (UIView *)BlueView{
    
    if (!_BlueView ) {
        
        _BlueView = [[UIView alloc] init];
        _BlueView.frame = CGRectMake(0, 0, SCREEN_WIDTH, UNIT_HEIGHT(50));
        _BlueView.backgroundColor = getColor(@"1E7CD2");
        
    }
    
    return _BlueView;
    
}

- (void)setupUI{
    self.titleView = [[LXScollTitleView alloc] initWithFrame:CGRectZero];
    __weak typeof(self) weakSelf = self;
    self.titleView.selectedBlock = ^(NSInteger index){
        __weak typeof(self) strongSelf = weakSelf;
        strongSelf.contentView.currentIndex = index;
    };
    self.titleView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    
    self.titleView.titleWidth = 90.f;
    self.titleView.normalColor = getColor(whiteColor);
    self.titleView.selectedColor = getColor(whiteColor);
    self.titleView.titleFont = DEF_FontSize_16;
    self.titleView.backgroundColor = getColor(@"1E7CD2");
    [self.view addSubview:self.titleView];
    
    self.contentView = [[LXScrollContentView alloc] initWithFrame:CGRectZero];
    self.contentView.scrollBlock = ^(NSInteger index){
        __weak typeof(self) strongSelf = weakSelf;
        strongSelf.titleView.selectedIndex = index;
    };
    [self.view addSubview:self.contentView];
}


- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    self.titleView.frame = CGRectMake(0, UNIT_HEIGHT(50), self.view.frame.size.width, 35);
    self.contentView.frame = CGRectMake(0,  35 + UNIT_HEIGHT(50), self.view.frame.size.width, SCREEN_HEIGHT - UNIT_HEIGHT(50) - 35 - height49 );
}

- (void)reloadData{
    
   
    
    NSArray *titles  = self.titleArr;
    [self.titleView reloadViewWithTitles:titles];
    
    NSMutableArray *vcs = [[NSMutableArray alloc] init];
    for (int i = 0;i<self.titleArr.count;i++) {
        VedioSonViewController *vc = [[VedioSonViewController alloc] init];
        
        vc.type = self.titleArr[i];
        
        vc.titleId = self.videoIdArr[i];
        
      
        
        [vcs addObject:vc];
    }
    [self.contentView reloadViewWithChildVcs:vcs parentVC:self];
}


#pragma mark --

- (NSMutableArray *)titleArr{
    
    if (!_titleArr) {
        
        _titleArr = @[].mutableCopy;
        
    }
    
    return _titleArr;
    
}

- (NSMutableArray *)videoIdArr{
    
    if (!_videoIdArr) {
        
        _videoIdArr = @[
                        
                        ].mutableCopy;
    }
    
    return _videoIdArr;
    
}



@end
